
package nothing.dao.hibernate;

import nothing.Util;
import nothing.model.Cooked;
import nothing.model.Purchase;
import nothing.dao.CookedDao;
import org.appfuse.dao.hibernate.GenericDaoHibernate;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

public class CookedDaoHibernate extends GenericDaoHibernate<Cooked, Long> implements CookedDao {

    public CookedDaoHibernate() {
        super(Cooked.class);
    }

    @SuppressWarnings("unchecked")
    public List<Cooked> findByMostCooked() {
        return getHibernateTemplate().find("from Cooked c order by c.when");
    }
    
    @SuppressWarnings("unchecked")
    public List<Cooked> findByLeastCooked() {
        return getHibernateTemplate().find("from Cooked c order by c.when desc ");
    }

    @SuppressWarnings("unchecked")
    public List<Cooked> findByRecipeName(String name) {
        List<Object[]> mess = getHibernateTemplate().find("from Cooked c, Recipe r where c.recipe=r and r.name=?", name);
        final List cooked = new ArrayList();
        cooked.addAll(Util.toList(mess,0));
        return cooked;
    }
}
